﻿package mortal.game.view.copy.groupCopy
{
    import Message.Public.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.GroupTowerCopy.data.*;
    import mortal.game.view.copy.GroupTowerCopy.panel.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.copy.groupCopy.data.*;
    import mortal.game.view.copy.groupCopy.view.*;
    import mortal.game.view.copy.groupCopy.view.singleCopyPanel.*;
    import mortal.game.view.copy.groupCopy.view.vipCopy.*;
    import mortal.game.view.copy.singleTowerCopy.panel.*;
    import mortal.game.view.copy.singleTowerCopy2.panel.*;
    import mortal.game.view.vip.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.interfaces.*;

    public class GroupCopyModule extends BaseWindow
    {
        private var _tabData:Array;
        private var _tabBar:GTabarNew;
        private var _currentPanel:GroupCopyBasePanel;
        private var _selIndex:String = null;
        public static const GroupCopy:String = "m1";
        public static const SingleCopy:String = "m2";
        public static const DefenCopy:String = "m3";
        public static const VipCopy:String = "m4";
        public static const GroupDefenCopy:String = "m5";
        public static const GroupCopyTower:String = "m6";
        public static const SingleTower:String = "m7";

        public function GroupCopyModule(param1:ILayer = null)
        {
            this._tabData = new Array();
            super(param1);
            setSize(895, 610);
            title = "" + Language.getString(70908);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tabBar = UIFactory.gTabBarNew(2, 32, this._tabData, 890, 590, 105, 26, this, this.tabBarChangeHandler);
            this.updateTab();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._selIndex = null;
            this._tabBar.dispose(param1);
            this._tabBar = null;
            this._tabData.length = 0;
            if (this._currentPanel)
            {
                this._currentPanel.dispose(param1);
                this._currentPanel = null;
            }
            GroupCopyUtil.checkRw();
            GroupCopyWaitingView.openCopy = false;
            super.disposeImpl(param1);
            return;
        }// end function

        public function updateTab() : void
        {
            var _loc_1:* = Cache.instance.role.roleEntityInfo.entityInfo.level;
            this._tabData = [];
            if (GameController.autoGuide.hasGuideGroupCopy())
            {
                this._tabData.push({name:"m1", label:"" + Language.getString(70909), num:3 - Cache.instance.copy.getGroupCopyEnterNum(ECopyType._ECopyTypeTeam)});
            }
            if (GameController.autoGuide.hasGuideCopyIcon())
            {
                this._tabData.push({name:"m2", label:"" + Language.getString(70910), num:3 - Cache.instance.copy.getGroupCopyEnterNum(ECopyType._ECopyTypeSingle)});
            }
            if (GameController.autoGuide.hasGuideDefenseCopy())
            {
                this._tabData.push({name:"m3", label:"" + Language.getString(70911), num:GroupTowerCopyUtil.getNumByGroup(112)});
            }
            if (GameController.autoGuide.hasTeamGuideDefenseCopy())
            {
                this._tabData.push({name:"m5", label:"" + Language.getString(70912), num:GroupTowerCopyUtil.getNumByGroup(138)});
            }
            if (LevelCheckUtil.isLevelEnougth(94))
            {
                this._tabData.push({name:"m7", label:"" + Language.getString(70914), num:GroupTowerCopyUtil.getSingleTowerCopyNum()});
            }
            if (LevelCheckUtil.isLevelEnougth(49))
            {
                this._tabData.push({name:"m4", label:"" + Language.getString(70915), num:VipUtil.vipCopyLeftNum});
            }
            this._tabBar.dataProvider = this._tabData;
            return;
        }// end function

        public function set selectedIndex(param1:String) : void
        {
            var _loc_3:int = 0;
            this._selIndex = param1;
            var _loc_2:* = this._tabBar.dataProvider;
            this._tabBar.selectedIndex = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                if (_loc_2[_loc_3].name == param1)
                {
                    this._tabBar.selectedIndex = _loc_3;
                    this.tabBarChangeHandler(null);
                    return;
                }
                _loc_3++;
            }
            this._tabBar.selectedIndex = 0;
            this.tabBarChangeHandler(null);
            return;
        }// end function

        private function tabBarChangeHandler(event:Event = null) : void
        {
            var _loc_2:* = this._tabBar.dataProvider[this._tabBar.selectedIndex];
            if (_loc_2)
            {
                Cache.instance.group.groupCopyTemporaryIndex = _loc_2.name;
                if (this._currentPanel)
                {
                    this._currentPanel.dispose(true);
                    this._currentPanel = null;
                }
                this.updatePanel();
            }
            return;
        }// end function

        private function updatePanel() : void
        {
            var _loc_1:* = this._tabBar.dataProvider[this._tabBar.selectedIndex].name;
            switch(_loc_1)
            {
                case GroupCopy:
                {
                    this.addGroupInfoPanel();
                    break;
                }
                case SingleCopy:
                {
                    this.addSinglePanel();
                    break;
                }
                case DefenCopy:
                {
                    this.addDefensePanel();
                    break;
                }
                case GroupDefenCopy:
                {
                    this.addGroupDefensePanel();
                    break;
                }
                case VipCopy:
                {
                    this.addVipCopyPanel();
                    break;
                }
                case GroupCopyTower:
                {
                    this.addGroupCopyTowerPanel();
                    break;
                }
                case SingleTower:
                {
                    this.addSingleCopyTowerPanel2();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function addGroupInfoPanel() : GroupCopyInfoPanel
        {
            this._currentPanel = UICompomentPool.getUICompoment(GroupCopyInfoPanel);
            this._currentPanel.x = 0;
            this._currentPanel.y = 55;
            this.addChild(this._currentPanel);
            return this._currentPanel as GroupCopyInfoPanel;
        }// end function

        private function addSinglePanel() : SingleCopyPanel
        {
            this._currentPanel = UICompomentPool.getUICompoment(SingleCopyPanel);
            this._currentPanel.x = 0;
            this._currentPanel.y = 55;
            this.addChild(this._currentPanel);
            return this._currentPanel as SingleCopyPanel;
        }// end function

        private function addDefensePanel() : GroupCopyDefensePanel
        {
            this._currentPanel = UICompomentPool.getUICompoment(GroupCopyDefensePanel);
            this._currentPanel.x = 0;
            this._currentPanel.y = 55;
            this.addChild(this._currentPanel);
            return this._currentPanel as GroupCopyDefensePanel;
        }// end function

        private function addGroupDefensePanel() : GroupCopyGroupDefensePanel
        {
            this._currentPanel = UICompomentPool.getUICompoment(GroupCopyGroupDefensePanel);
            this._currentPanel.x = 0;
            this._currentPanel.y = 55;
            this.addChild(this._currentPanel);
            return this._currentPanel as GroupCopyGroupDefensePanel;
        }// end function

        private function addVipCopyPanel() : VipCopyPanel
        {
            this._currentPanel = UICompomentPool.getUICompoment(VipCopyPanel);
            this._currentPanel.x = 0;
            this._currentPanel.y = 55;
            this.addChild(this._currentPanel);
            return this._currentPanel as VipCopyPanel;
        }// end function

        private function addGroupCopyTowerPanel() : GroupCopyTowerPanel
        {
            this._currentPanel = UICompomentPool.getUICompoment(GroupCopyTowerPanel);
            this._currentPanel.x = 0;
            this._currentPanel.y = 55;
            this.addChild(this._currentPanel);
            return this._currentPanel as GroupCopyTowerPanel;
        }// end function

        private function addSingleCopyTowerPanel() : SingleTowerCopyPanel
        {
            this._currentPanel = UICompomentPool.getUICompoment(SingleTowerCopyPanel);
            this._currentPanel.x = 0;
            this._currentPanel.y = 55;
            this.addChild(this._currentPanel);
            return this._currentPanel as SingleTowerCopyPanel;
        }// end function

        private function addSingleCopyTowerPanel2() : SingleTowerCopyPanel2
        {
            this._currentPanel = UICompomentPool.getUICompoment(SingleTowerCopyPanel2);
            this._currentPanel.x = 9;
            this._currentPanel.y = 61;
            this.addChild(this._currentPanel);
            return this._currentPanel as SingleTowerCopyPanel2;
        }// end function

        public function updateGroupList(param1:SCopyWaitingGroupMsg) : void
        {
            if (this._currentPanel is GroupCopyInfoPanel)
            {
                (this._currentPanel as GroupCopyInfoPanel).updateGroupList(param1);
            }
            else if (this._currentPanel is GroupCopyGroupDefensePanel)
            {
                (this._currentPanel as GroupCopyGroupDefensePanel).updateGroupList(param1);
            }
            else if (this._currentPanel is GroupCopyTowerPanel)
            {
                (this._currentPanel as GroupCopyTowerPanel).updateGroupList(param1);
            }
            return;
        }// end function

        public function updateTeamMate() : void
        {
            if (this._currentPanel is GroupCopyInfoPanel)
            {
                (this._currentPanel as GroupCopyInfoPanel).updateGroupMateList();
            }
            else if (this._currentPanel is GroupCopyGroupDefensePanel)
            {
                (this._currentPanel as GroupCopyGroupDefensePanel).updateGroupMateList();
            }
            else if (this._currentPanel is GroupCopyTowerPanel)
            {
                (this._currentPanel as GroupCopyTowerPanel).updateGroupMateList();
            }
            return;
        }// end function

        public function updateGroupCopyEnterNum() : void
        {
            if (this._currentPanel is GroupCopyInfoPanel)
            {
                (this._currentPanel as GroupCopyInfoPanel).updateLimitNum();
            }
            else if (this._currentPanel is GroupCopyGroupDefensePanel)
            {
                (this._currentPanel as GroupCopyGroupDefensePanel).updateLimitNum();
            }
            else if (this._currentPanel is GroupCopyTowerPanel)
            {
                (this._currentPanel as GroupCopyTowerPanel).updateLimitNum();
            }
            return;
        }// end function

        public function updateBoRwAfterGet() : void
        {
            if (this._currentPanel is GroupCopyDefensePanel)
            {
                (this._currentPanel as GroupCopyDefensePanel).updateBoRwAfterGet();
            }
            else if (this._currentPanel is GroupCopyGroupDefensePanel)
            {
                (this._currentPanel as GroupCopyGroupDefensePanel).updateBoRwAfterGet();
            }
            return;
        }// end function

        public function updateVipCopyList() : void
        {
            if (this._currentPanel is VipCopyPanel)
            {
                (this._currentPanel as VipCopyPanel).updateCopyList();
            }
            return;
        }// end function

        override public function hide() : void
        {
            if (GroupCopyWaitingView.isViewShow)
            {
                this.hideToTarget(GroupCopyWaitingView.instance);
            }
            super.hide();
            return;
        }// end function

    }
}
